package com.uenpay.im.ui.old.activity.transfer;

import com.qiyunxin.android.http.listener.OnHttpRequestTextListener;
import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.qiyunxin.android.http.net.HttpRequestAsyncTaskQueue;
import com.qiyunxin.android.http.net.HttpRequestType;
import com.qiyunxin.android.http.net.HttpTextAsyncTask;
import com.uenpay.im.IMApplication;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * @E-mail:
 * @date 创建时间：2016-5-6 下午9:42:34
 * @version 1.0
 * @function 支付详情
 */
public class TransferHandle {

	public interface ITarsferListener {
		void getTarsferResult(int status, String msg,
											  TransferEntity mTransferEntity);
	}

	public static void getTransferDetail(String turnoverid,
			final ITarsferListener mITarsferListener) {
		GetTransferDetailInvokItem item = new GetTransferDetailInvokItem(
				turnoverid);
		HttpRequestAsyncTaskQueue
				.getInstance()
				.AddTask(
						new HttpTextAsyncTask(item)
								.SetRequestType(HttpRequestType.SERVER_FAIL_AND_CACHE),
						new OnHttpRequestTextListener() {

							@Override
							public void OnFail(boolean isCache, String reason) {
								IMApplication.showToast(reason);
							}

							@Override
							public void OnProgress(long total_bytes,
									long downloaded_bytes) {
							}

							@Override
							public void OnSuccess(HttpInvokeItem item,
									boolean isCache, String cacheFilePath) {
								GetTransferDetailInvokItem.GetTransferDetailInvokItemResult result = ((GetTransferDetailInvokItem) item)
										.getOutput();
								if (result != null) {
									mITarsferListener.getTarsferResult(
											result.status, result.msg,
											result.transferEntity);
								}
							}
						});

	}


	public interface ITransferLisener {
		void onTransferResult(int status, String msg);
	}

	/**
	 * 转账
	 *
	 * @param custid
	 * @param amount
	 * @param targettotal
	 * @param paypassword
	 */
	public static void transferToPersonal(String custid, String amount,
			String targettotal, String paypassword,String memo,
			final ITransferLisener mITransferLisener) {
		TransferInvokItem item = new TransferInvokItem(custid, amount,
				targettotal, paypassword,memo);
		HttpRequestAsyncTaskQueue
				.getInstance()
				.AddTask(
						new HttpTextAsyncTask(item)
								.SetRequestType(HttpRequestType.SERVER_FAIL_AND_CACHE),
						new OnHttpRequestTextListener() {

							@Override
							public void OnFail(boolean isCache, String reason) {
								mITransferLisener.onTransferResult(-1, reason);
							}

							@Override
							public void OnProgress(long total_bytes,
									long downloaded_bytes) {
							}

							@Override
							public void OnSuccess(HttpInvokeItem item,
									boolean isCache, String cacheFilePath) {
								TransferInvokItem.TransferInvokItemResult result = ((TransferInvokItem) item)
										.getOutput();
								if (result != null) {
									mITransferLisener.onTransferResult(
											result.status, result.msg);
								} else {
									mITransferLisener.onTransferResult(-1, "");
								}
							}

						});
	}
}
